package system

import (
	"gitee.com/liukexing/mqbroker/component/system/httprequest"
	"gitee.com/liukexing/mqbroker/core/driver/config"
	"gitee.com/liukexing/mqbroker/core/typedef"
	"sync"
)

const (
	ConfigName = "config.component.system"
)

var (
	Deamon typedef.SubHandle = Run
	RunModule []string
	submodule sync.Map
	Config    typedef.ConfigInfo
)
func init() {
	var ok bool
	Config, ok = config.GetConfig(ConfigName)
	if !ok {
		return
	}
	if !Config.Info.Enable {
		return
	}
}

func registerModel() {
	submodule.Store("httprequest",httprequest.Deamon)
	//submodule.Store("httpreply",httpreply.Deamon)
	//submodule.Store("httpclient",httpclient.Deamon)
}
func initSubModule(module string) bool {
	if !Config.Info.Enable {
		return true
	}
	if subfun, ok := submodule.Load(module); ok {
		return subfun.(typedef.SubHandle)()
	}
	return true
}

func Run() bool {
	if !Config.Info.Enable {
		return true
	}
	registerModel()
	for _, v := range Config.Info.SubModule {
		if !initSubModule(v) {
			RunModule = append(RunModule, v)
		}
	}
	return false
}
